details-mappers.ts ➔ mapNodeToTreeStructure   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
1
import { TreeNode } from '../components/types';
2
3
export interface TreeStructure {
4
    name: string;
5
    children?: TreeStructure[];
6
}
7
8
type TreeNodeWithVisitedFlag = TreeNode & { isVisited?: boolean };
9
10
export function mapNodeToTreeStructure(node: TreeNodeWithVisitedFlag, linksType: 'consumers' | 'providers'): TreeStructure {
11
    node.isVisited = true;
12
    const unvisitedLinks = node[linksType].filter((linkedNode: TreeNodeWithVisitedFlag) => !linkedNode.isVisited && linkedNode[linksType]);
13
    const children = unvisitedLinks.map(nestedNode => mapNodeToTreeStructure(nestedNode, linksType));
14
    node.isVisited = undefined;
15
    return { name: node.name, children };
16
}
17